package com.xx.chb01.design.factory;

import com.xx.chb01.design.factory.entity.CountEntry;
import com.xx.chb01.design.factory.entity.CountRecoder;
import com.xx.chb01.utils.json.JsonUtils;

import java.util.LinkedList;
import java.util.List;

/**
 * @Auther: chb
 * @Date: 2018/12/19 11:50
 * @Description:  这样写是有问题的   很难维护   ff包里面 用了 工厂设计模式
 */
public class Test01 {


	public static void main(String[] args) {
		//保存一天之中六种状态分别对应的数据条目
		List<CountEntry> countEntries =new LinkedList<>();
		CountEntry countEntry=new CountEntry();
		countEntry.setCount(200);
		countEntry.setCode(1);
		countEntries.add(countEntry);
		getCountRecoder(countEntries);
	}

	public static CountRecoder getCountRecoder(List<CountEntry> countEntries)
	{
		CountRecoder countRecoder=new CountRecoder();
		for (CountEntry countEntry : countEntries) {
			if (1 == countEntry.getCode()) {
				countRecoder.setFirstStage(countEntry.getCount());
			} else if (2 == countEntry.getCode()) {
				countRecoder.setSecondStage(countEntry.getCount());
			} else if (3 == countEntry.getCode()) {
				countRecoder.setThirdStage(countEntry.getCount());
			} else if (4 == countEntry.getCode()) {
				countRecoder.setFourStage(countEntry.getCount());
			} else if (5 == countEntry.getCode()) {
				countRecoder.setFiveStage(countEntry.getCount());
			} else if (6 == countEntry.getCode()) {
				countRecoder.setSixStage(countEntry.getCount());
			}
		}
		System.out.println(JsonUtils.toJSONString(countRecoder));
		return countRecoder;
	}

}
